import { ErrorBoundary } from "solid-js";

export default function ErrorView() {
  return (
    <ErrorBoundary fallback={(error) => <ErrorRenderer error={error} />}>
      <ThrowError throwError />
    </ErrorBoundary>
  );
}

function ThrowError(p: { throwError: boolean }) {
  if (p.throwError) {
    throw new Error("Aha!");
  }
  return <div>{p.throwError}</div>;
}

function ErrorRenderer(p: { error: unknown }) {
  if (p.error instanceof Error) {
    return <div>💥{p.error.message}</div>;
  }
  return <div>💥 unknown error!</div>;
}
